package com.onlyxiahui.extend.query.hibernate.syntax.util;

import java.util.Map;
import java.util.Set;

import com.onlyxiahui.extend.query.hibernate.QueryWrapper;

/**
 * 
 * Description <br>
 * Date 2020-02-01 11:32:44<br>
 * 
 * @author XiaHui [onlovexiahui@qq.com]<br>
 * @since 1.0.0
 */
public class InsertHqlUtil {

	public static String getInsertHql(String beanName, String idName, QueryWrapper qw) {

		StringBuilder sql = new StringBuilder();
		Map<String, Object> map = (null == qw) ? null : qw.getParameterMap();
		if (map != null && !map.isEmpty()) {
			Set<String> keySet = map.keySet();
			sql.append(" insert into ");
			sql.append(beanName);

			sql.append(" (");
			int i = 0;
			// int size=keySet.size();
			for (String key : keySet) {
				i++;
				if (i == 1) {
					sql.append(key);
				} else {
					sql.append(",");
					sql.append(key);
				}
			}
			sql.append(")");

			sql.append(" values(");
			i = 0;
			for (String key : keySet) {
				i++;
				if (i == 1) {
					sql.append(":");
					sql.append(key);
				} else {
					sql.append(",");
					sql.append(":");
					sql.append(key);
				}
			}
			sql.append(")");
		}
		return sql.toString();
	}
}
